package com.ksd.modules.members.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ksd.common.annotation.ApiLog;
import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.common.po.BatchIdsPO;
import com.ksd.common.web.annotation.RepeatSubmit;
import com.ksd.modules.members.po.AdminUserVipSavePO;
import com.ksd.modules.members.po.AdminUserVipSearchPO;
import com.ksd.modules.members.service.IAdminUserVipService;
import com.ksd.modules.members.vo.AdminUserVipVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 平台up主用户 前端控制器
 * </p>
 *
 * @author Auto Generator
 * @since 2023-08-15
 */
@RestController
public class AdminUserVipController extends BaseController {


    @Autowired
    private IAdminUserVipService adminUserVipService;

    /**
     * 查询首页平台会员卡模板接口
     * @param adminUserVipSearchPO
     * @return
     */
    @PostMapping("/users/vip/list")
    public R<Page<AdminUserVipVo>> findAdminUserVips(@Validated @RequestBody AdminUserVipSearchPO adminUserVipSearchPO){
        return R.data(adminUserVipService.findAdminUserVips(adminUserVipSearchPO));
    }

    /**
     * 【平台会员卡】- 回收站
     * @return
     */
    @PostMapping("/users/vip/recyle")
    public R<Page<AdminUserVipVo>> findAdminUserVipsRecyle(@Validated @RequestBody AdminUserVipSearchPO adminUserVipsSearchPO){
        return R.data(adminUserVipService.findAdminUserVipsRecyle(adminUserVipsSearchPO));
    }

    /**
     * 【平台会员卡】 - 保存和更新
     * @param adminUserVipsSavePO
     * @return
     */
    @PostMapping("/users/vip/saveupdate")
    @ApiLog("【平台会员卡】 - 保存和更新")
    @RepeatSubmit
    public R<AdminUserVipVo> saveUpdateAdminUserVip(@Validated @RequestBody AdminUserVipSavePO adminUserVipsSavePO){
        return R.data(adminUserVipService.saveUpdateAdminUserVip(adminUserVipsSavePO));
    }

    /**
     * 【平台会员卡】 - 根据id查询明细
     * @param id
     * @return
     */
    @PostMapping("/users/vip/get/{id}")
    public R<AdminUserVipVo> getAdminUserVipById(@PathVariable("id")Long id){
        return R.data(adminUserVipService.getAdminUserVipById(id));
    }

    /**
     * 【平台会员卡】 - 根据id删除平台会员卡
     * @param id
     * @return
     */
    @PostMapping("/users/vip/del/{id}")
    @ApiLog("【平台会员卡】 - 根据id删除平台会员卡 ")
    public R<Boolean> deleteAdminUserVipById(@PathVariable("id")Long id){
        return R.data(adminUserVipService.deleteAdminUserVipById(id));
    }

    /**
     * 【平台会员卡】- 根据id恢复删除
     *
     * @param id
     * @return
     */
    @PostMapping("/users/vip/recover/{id}")
    @ApiLog("【平台会员卡】- 根据id恢复删除")
    @RepeatSubmit
    public R<Boolean> recoverByIdAdminUserVip(@PathVariable("id") Long id) {
        return R.data(adminUserVipService.recoverByIdAdminUserVip(id));
    }

    /**
     * 【平台会员卡】- 批量逻辑删除
     *
     * @return
     */
    @PostMapping("/users/vip/batch/dels")
    @ApiLog("【平台会员卡】- 批量逻辑删除")
    @RepeatSubmit
    public R<Boolean> bacthDeletesAdminUserVip(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserVipService.bacthDeletesAdminUserVip(batchIdsPO));
    }


    /**
     * 【平台会员卡】- 批量恢复
     *
     * @return
     */
    @PostMapping("/users/vip/batch/recover")
    @ApiLog("【平台会员卡】- 批量恢复")
    @RepeatSubmit
    public R<Boolean> batchRecoversAdminUserVip(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserVipService.batchRecoversAdminUserVip(batchIdsPO));
    }

    /**
     * 【平台会员卡】- 批量物理删除
     *
     * @return
     */
    @PostMapping("/users/vip/batch/remove")
    @ApiLog("【平台会员卡】- 批量物理删除")
    @RepeatSubmit
    public R<Boolean> batchRemovesAdminUserVip(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserVipService.batchRemovesAdminUserVip(batchIdsPO));
    }

    /**
     * 【平台会员卡】- 根据ID恢复删除
     * @param id
     * @return
     */
    @PostMapping("/users/vip/remove/{id}")
    @ApiLog("【平台会员卡】- 根据ID恢复删除")
    public R<Boolean> removeAdminUserVipById(@PathVariable("id")Long id){
        return R.data(adminUserVipService.removeAdminUserVipById(id));
    }

    /**
     * 【平台会员卡】- 修改状态
     *
     * @return
     */
    @PostMapping("/users/vip/status/{id}/{field}")
    @ApiLog("【平台会员卡】- 修改状态")
    @RepeatSubmit
    public R<Boolean> updateStatus(
            @PathVariable("id") Long id,
            @PathVariable("field") String field,
            @RequestParam("value") String value
    ) {
        if(StringUtils.isNumeric(value)) {
            return R.data(adminUserVipService.updateStatus(id, field, Integer.parseInt(value)));
        }else{
            return R.data(adminUserVipService.updateStatusStr(id, field, String.valueOf(value)));
        }
    }

    /**
     * 【下载】-批量上架
     *
     * @return
     */
    @PostMapping("/users/vip/batch/up")
    @ApiLog("【下载】-批量上架")
    @RepeatSubmit
    public R<Boolean> batchUps(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserVipService.batchUps(batchIdsPO));
    }

    /**
     * 【下载】-批量下架
     *
     * @return
     */
    @PostMapping("/users/vip/batch/down")
    @ApiLog("【下载】-批量下架")
    @RepeatSubmit
    public R<Boolean> batchDowns(@RequestBody BatchIdsPO batchIdsPO) {
        return R.data(adminUserVipService.batchDowns(batchIdsPO));
    }
}
